<html>
<head>

	<script src="jquery-1.3.1.min.js"></script>
	<script src="jquery-ui-1.7.custom.min.js"></script>
	
	<script>

	$(document).ready(function(){
		$("#register").click(function(){register()});
		$("#add").click(function(){add()});
		$("#remove").click(function(){remove()});
		$("#getlist").click(function(){getbuddylist()});
		$("#sendmessage").click(function(){sendmessage()});
		$("#login").click(function(){login()});
		$("#history").click(function(){getHistory()});
	});
	
	function add(){
	var clientid = $("#clientid")[0].value;
	var buddy = $("#buddyname")[0].value;
	var addBuddyURL = "http://tornado.ics.uci.edu:8080/pimp/WebResponder?&type=addbuddy&clientID="+clientid+"&buddy="+buddy+"&group=parents";
	
		$.get(addBuddyURL, function(data){
			alert("data:" + data);
		});
	}
	
	function register(){
	var clientid = $("#clientid")[0].value;
	var registerURL = "http://tornado.ics.uci.edu:8080/pimp/WebResponder?&type=register&clientID="+clientid+"&password=password";
		$.get(registerURL, function(data){
			alert("data:" + data);
		});
	}
		
	function remove(){
	var clientid = $("#clientid")[0].value;
	var buddy = $("#buddyname")[0].value;
	var removeBuddyURL = "http://tornado.ics.uci.edu:8080/pimp/WebResponder?&type=removebuddy&clientID="+clientid+"&buddy="+buddy+"&group=parents";

		$.get(removeBuddyURL, function(data){
			alert("data:" + data);
		});
	}
	
	function getbuddylist(){
	var clientid = $("#clientid")[0].value;
	var buddylisturl = "http://tornado.ics.uci.edu:8080/pimp/WebResponder?&type=getbuddylist&clientID="+clientid;
	
		$.getJSON(buddylisturl, function(data){
			alert("data:" + data + "  "+ data.status);
		});
	}
	
	function sendmessage(){
	var from = $("#clientid")[0].value;
	var to = $("#buddyname")[0].value;
	var message = $("#message")[0].value;
	var imtype = 0;
	var sendmessageURL = "http://tornado.ics.uci.edu:8080/pimp/WebResponder?&type=sendmessage&clientID="+clientid+"&to="+to+"&from="+from+"&message="+message+"&imtype="+imtype;
	
		$.get(sendmessageURL, function(data){
			alert("data:" + data);
		});
	}
	
	function login(){
		var clientid = $("#clientid")[0].value;
		var password = $("#password")[0].value;
		var loginurl = "http://tornado.ics.uci.edu:8080/pimp/WebResponder?&type=login&loginID="+clientid+"&password="+password;
		
		$.get(loginurl, function(data){
			alert("data:" + data);
		});
	}
	
	function getHistory(){
		var clientid = $("#clientid")[0].value;
		var loginurl = "http://tornado.ics.uci.edu:8080/pimp/WebResponder?&type=gethistory&loginID="+clientid;
		
		$.get(loginurl, function(data){
			alert("data:" + data);
		});
	}
	
	</script>
</head>
<body>
Client ID:<input id="clientid" type="text" name="clientid"> 
Password:<input id="password" type="text" name="password"> <br />
Buddy Name:<input id="buddyname" type="text" name="buddyname"><br />
Message:<input id="message" type="text" name="message">
<div><span id="register" href="#">register</span></div>
<div><span id="add" href="#">add buddy</span></div>
<div><span id="remove" href="#">remove buddy</span></div>
<div><span id="getlist" href="#">get buddy list</span></div>
<div><span id="sendmessage" href="#">sendmessage</span></div>
<div><span id="login" href="#">login</span></div>
<div><span id="history" href="#">chat history</span></div>
</body>
</html>
	